package bp.net;

import java.util.ArrayList;
import java.util.List;

public class NeuroLayer extends Layer{

	protected Layer preLayer;
	
	@SuppressWarnings("unchecked")
	public NeuroLayer(int count,Layer preLayer) {
		this.preLayer = preLayer;
		this.nerves = new ArrayList<NeuroNerve>();
		for(int i=0;i<count;i++){
			this.getNerves().add(new NeuroNerve(this));
		}
	}
	
	@SuppressWarnings("unchecked")
	public NeuroLayer(List<List<Double>> weights, Layer preLayer) {
		this.preLayer = preLayer;
		this.nerves = new ArrayList<NeuroNerve>();
		for(int i=0;i<weights.size();i++){
			this.getNerves().add(new NeuroNerve(this,weights.get(i)));
		}
	}

	public void compute(){
		for(Object o:this.nerves){
			NeuroNerve nn = (NeuroNerve)o;
			nn.compute();
		}
	}
	
	public void setWeights(List<List<Double>> weights){
		for(int i=0;i<weights.size();i++){
			((NeuroNerve)this.nerves.get(i)).setWeights(weights.get(i));
		}
	}
	
	public List<List<Double>> getWeights(){
		List<List<Double>> list = new ArrayList<List<Double>>();
		for(int i=0;i<this.nerves.size();i++){
			NeuroNerve n = (NeuroNerve) this.nerves.get(i);
			list.add(n.getWeights());
		}
		return list;
	}
	
	public int getNervesCount(){
		return this.getNerves().size();
	}

	public Layer getPreLayer() {
		return preLayer;
	}
}
